package edu.zsl.service.impl;

import edu.zsl.mapper.StudentMapper;
import edu.zsl.pojo.Student;
import edu.zsl.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
@Service
public class StudentServiceImpl implements StudentService {
    private final StudentMapper studentMapper;
    @Autowired
    public StudentServiceImpl(StudentMapper studentMapper) {
        this.studentMapper = studentMapper;
    }

    @Override
    public List<Student> getAllStudents() {
        return studentMapper.getAllWithGender();
    }
    @Override
    public void insertStudent(Student student) {
        // 添加学生之前，需要先创建账号
        studentMapper.insertStudent(student);
    }


    @Override
    public Student getStudentById(String id) {
        Student student = studentMapper.getById(id);
        return student;
    }

    @Override
    public void updateStudent(Student student) {
        student.setUpdateBy(1);
        student.setUpdateTime(LocalDateTime.now());
        studentMapper.update(student);
    }

}
